package com.lmm.lcbusiness.lcbusiness.pages.richtxt;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;

import com.lmm.lcbusiness.lcbusiness.AppBaseActivity;
import com.lmm.lcbusiness.lcbusiness.R;

/**
 * Created by xmgong on 2017/6/29.
 * 图文文字编辑
 */
public class RichTxtEditActivity extends AppBaseActivity {

    String curRich = "";
    EditText editText;
    int curIndex = -1;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_richedit);
        setActionBarTitle("文字编辑");
        editText = findViewById(R.id.et);

        if (getIntent().hasExtra("richmodel")) {
            curRich = getIntent().getStringExtra("richmodel");
            editText.setText(curRich);
        }

        if (getIntent().hasExtra("index")) {
            curIndex = getIntent().getIntExtra("index", -1);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_save, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        super.onOptionsItemSelected(item);
        if (item.getItemId() == R.id.action_save) {
            Intent mintent = new Intent();
            mintent.putExtra("index", curIndex);
            mintent.putExtra("value", editText.getText().toString());
            setResult(RESULT_OK, mintent);
            finish();
        }
        return true;
    }
}
